var thisAllInfo;
var privatenotesid=new Array();
var AllInfoMediator = Objs("view.AllInfoMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{  
		AllInfoMediator.$super.initialize.call( this, name, viewComponent );
    	this.VProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.assetProxy = this.facade.retrieveProxy( ProxyNames.INITIAL_PROXY );
		this.registerListeners();
		thisAllInfo=this;
	
		
		
		
	},
	registerListeners: function()
	{  
		var allInfoPageView = this.get();
		allInfoPageView.addEventListener( AllInfoPage.ADD_MESSAGE, this.addMessageHandler, this );
		allInfoPageView.addEventListener( AllInfoPage.ADD_PNOTE, this.addPnoteHandler, this );
	},
	get: function()
	{
		return this.viewComponent;
	},
	unregisterListeners: function()
	{
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.ADD_MESSAGE_SUCCESS,
				NotificationNames.ADD_PNOTE_SUCCESS	,
				NotificationNames.SETALLVALUE,
				NotificationNames.ADDNEW_PNOTE_SUCCESS
				
		];
	},
    handleNotification: function( note )
	{ 
		
		switch (note.getName() )
		{ 
			case NotificationNames.ADD_MESSAGE_SUCCESS:
				vehicleSingle.messages=[];				
				var messages=note.getBody().message;
				for(i=0;i<messages.length;i++)
				{
					vehicleSingle.messages.push(messages[i]);
				}
				this.setmesvalue();
			//	$('#message-modal').modal('hide');
				break;
			case NotificationNames.ADD_PNOTE_SUCCESS:
				
				this.setpnotevalue();
			//	$('#privatenote-modal').modal('hide');
				break;
			
			case NotificationNames.SETALLVALUE:
				this.setvalue();			
		}
	},
	addMessageHandler:function()
	{
		if(this.facade.hasMediator(MediatorNames.MESSAGE_POP_MEDIATOR)==false)
		{								
			var messagepopPage = new MessagepopPage();   
			var messagepopMediator = new MessagepopMediator( MediatorNames.MESSAGE_POP_MEDIATOR, messagepopPage);
			this.facade.registerMediator( messagepopMediator );
		}
		 
	},
	addPnoteHandler:function()
	{
		if(this.facade.hasMediator(MediatorNames.PNOTE_POP_MEDIATOR)==false)
		{								
			var pnotepopPage = new PrivateNotePage();   
			var pnotepopMediator = new PrivateNoteMediator( MediatorNames.PNOTE_POP_MEDIATOR, pnotepopPage);
			this.facade.registerMediator( pnotepopMediator );
			
		}
		 
	},
	setmesvalue:function()
	{
		document.getElementById("list_correspond").innerHTML = '';
		var meshtml=''
		for(var i=0;i<vehicleSingle.messages.length;i++)
		{ 
			 meshtml+="<div class='commentBox'> <div id=messagehead style='border-bottom:solid 1px #CCC'><strong>On " +vehicleSingle.messages[i].dateTime+ " " +vehicleSingle.messages[i].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.messages[i].message+ "</div></div>"; 
		}
		
		document.getElementById("list_correspond").innerHTML = meshtml;
	},
	
	setpnotevalue:function()
	{  
		document.getElementById("list_private").innerHTML='';
		var prihtml=''
		for(var j=0;j<vehicleSingle.private_notes.length;j++)
		{ 
			prihtml+="<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +vehicleSingle.private_notes[j].dateTime+ " " +vehicleSingle.private_notes[j].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.private_notes[j].message+ "</div></div>"; 
		}
		document.getElementById("list_private").innerHTML=prihtml;
	},
	setvalue:function()
	{
		currentid=vehicleSingle.vehicle_id;
		currentemail=vehicleSingle.email;
		currentname=vehicleSingle.first_name;
		currentnotes=vehicleSingle.private_notes;
		$("#allinfo_correspondence").show();
		$("#topsettingsinfo").show();
        $("#printpage").attr("href", "print-page.php?id="+vehicleSingle.vehicle_id +"")   
        $("#createreciept").attr("href", "receipt.php?id="+vehicleSingle.vehicle_id +"")   
		if(vehicleSingle.state==0)
		vehicleSingle.state='';
		document.getElementById('year').value = vehicleSingle.year;
		document.getElementById('make').value = vehicleSingle.make;
		this.assetProxy.setmodel();
		document.getElementById('vehicle-idmakemodel').innerHTML = vehicleSingle.vehicle_id + '-' + vehicleSingle.make_name + '  ' + vehicleSingle.model_name;
		document.getElementById('vehicle-yearmakemodel').innerHTML = vehicleSingle.year+ ' ' + vehicleSingle.make_name + '  ' + vehicleSingle.model_name;
		document.getElementById('vehicle-status').innerHTML =  vehicleSingle.status;
		document.getElementById('btn-status').innerHTML =  vehicleSingle.status;
		document.getElementById('vehicle-createdby').innerHTML =  vehicleSingle.created_by;
		document.getElementById('vehicle-citystate').innerHTML =  vehicleSingle.city+ ' / ' +vehicleSingle.state;
		document.getElementById('vehicle-askingprice').innerHTML =  '$'+vehicleSingle.asking_price;
		document.getElementById('vehicle-createddate').innerHTML =  vehicleSingle.created_date;
		 	$('select#make').change(function() {
				
				vehicleSingle.model=''
				thisObject.assetProxy.setmodel();
			});		
		document.getElementById('mileage').value = vehicleSingle.mileage;
		document.getElementById('great').value = vehicleSingle.great;
		document.getElementById('wrong').value = vehicleSingle.wrong;
		document.getElementById('paper_work').value = vehicleSingle.paper_work;
		document.getElementById('title').value = vehicleSingle.title_name;
		document.getElementById('title_note').value = vehicleSingle.title_note;
		if(vehicleSingle.ad_source)
		document.getElementById('ad_source').value = vehicleSingle.ad_source;
		else
		document.getElementById('ad_source').value = 0;
		document.getElementById('vin').value = vehicleSingle.vin;
		if(vehicleSingle.drivetrain_type)
		document.getElementById('drive_train_type').value = vehicleSingle.drivetrain_type;
		else
		document.getElementById('drive_train_type').value = 0;
		if(vehicleSingle.engine)
		document.getElementById('engine').value = vehicleSingle.engine;
		else
		document.getElementById('engine').value = 0;
		if(vehicleSingle.transmission)
		document.getElementById('transmission').value = vehicleSingle.transmission;
		else
		document.getElementById('transmission').value =0;
		document.getElementById('first_name').value = vehicleSingle.first_name;
		document.getElementById('business_name').value = vehicleSingle.business_name;
		document.getElementById('contact_name').value = vehicleSingle.contact_name;
		document.getElementById('street_address').value = vehicleSingle.street_address;
		document.getElementById('city').value = vehicleSingle.city;
		if(vehicleSingle.state)
		document.getElementById('state').value = vehicleSingle.state;
		else
		document.getElementById('state').value = 0;
		document.getElementById('zip').value = vehicleSingle.zip;
		document.getElementById('phone').value = vehicleSingle.phone;
		document.getElementById('cell_phone').value = vehicleSingle.cell_phone;
		document.getElementById('e_mail').value = vehicleSingle.email;
		if(vehicleSingle.contact_me)
		document.getElementById('contact_method').value = vehicleSingle.contact_me;
		else
		document.getElementById('contact_method').value = 0;
		document.getElementById('seller_note').value = vehicleSingle.contact_note;
		
		document.getElementById('v_address').value = vehicleSingle.v_street_address;
		document.getElementById('v_city').value = vehicleSingle.v_city;
		if(vehicleSingle.v_state)
		document.getElementById('v_state').value = vehicleSingle.v_state;
		else
		document.getElementById('v_state').value = 0;
		document.getElementById('v_zip').value = vehicleSingle.v_zip;
		if(vehicleSingle.delivery)
		document.getElementById('delivery').value = vehicleSingle.delivery;
		else
		document.getElementById('delivery').value=0;
		document.getElementById('remove_by').value = vehicleSingle.remove_by;
		document.getElementById('transport_note').value = vehicleSingle.delivery_note;
		if(vehicleSingle.i_want_to)
		document.getElementById('i_want_to').value = vehicleSingle.i_want_to;
		else
		document.getElementById('i_want_to').value = 0;
		if(vehicleSingle.delivery_option)
		document.getElementById('delivery_option').value = vehicleSingle.delivery_option;
		else
		document.getElementById('delivery_option').value = 0;
		document.getElementById('asking_price').value = vehicleSingle.asking_price;
		document.getElementById('bid_price').value = vehicleSingle.bid_price;
		document.getElementById('accepted_price').value = vehicleSingle.accepted_price;
		document.getElementById("list_correspond").innerHTML = '';
		document.getElementById("model-poplist").innerHTML = '';
		var meshtml=''
		for(var i=0;i<vehicleSingle.messages.length;i++)
		{ 
			 meshtml+="<div class='commentBox'> <div id=messagehead style='border-bottom:solid 1px #CCC'><strong>On " +vehicleSingle.messages[i].dateTime+ " " +vehicleSingle.messages[i].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.messages[i].message+ "</div></div>"; 
		}
		
		document.getElementById("list_correspond").innerHTML = meshtml;
		document.getElementById("model-poplist").innerHTML = meshtml;
		
		document.getElementById("list_private").innerHTML = '';
		var prihtml=''
		for(var j=0;j<vehicleSingle.private_notes.length;j++)
		{ 
			prihtml+="<div class='commentBox'> <div style='border-bottom:solid 1px #CCC' id=messagehead ><strong>On " +vehicleSingle.private_notes[j].dateTime+ " " +vehicleSingle.private_notes[j].messageOwener+ " Wrote</strong></div><div id=messagedetail style='padding-bottom:10px;'>" +vehicleSingle.private_notes[j].message+ "</div></div>"; 
		}
		document.getElementById("list_private").innerHTML=prihtml;
		document.getElementById("privatenotemodel").innerHTML=prihtml;
		if(vehicleSingle.images.length>0)
		{   
				
				document.getElementById("galleryhead").innerHTML="<h3>Vehicle Images</h3>";
			for(i=0;i<vehicleSingle.images.length;i++)
			{ 
			
						document.getElementById("imageul").innerHTML+="  <li ><a  href=../"+vehicleSingle.images[i].cropUrl+ "><img class=thumbnail style=float:left;margin:5px; src=../"+vehicleSingle.images[i].thumpUrl+" width=72 height=72 alt=''></a></li>";			
						 $('#gallery a').lightBox(); 
						
			}
		}

	}
	
	
	
});

